from selenium.webdriver.common.by import By
import time
from common.Utils import TestDriver
import datetime
from selenium.webdriver.common.keys import Keys


class UC:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://127.0.0.1:58080/sign-in.html"
        self.driver = TestDriver.driver
        self.driver.get(self.url)

    #测试用户中心

    def UCMyblog(self):
        self.driver.implicitly_wait(3)
        #登录
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lisi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert actual1 == "首页"
        #进入我的帖子
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_profile").click()

        #查看基本信息
        self.driver.find_element(By.CSS_SELECTOR,"#profile_avatar")
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3)")
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div > h2")
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col > ul > li")

        #查看帖子
        self.driver.find_element(By.CSS_SELECTOR,"#profile_article_body > li:nth-child(25) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_title")
        self.driver.refresh()

    def UCMycenter(self):
        self.driver.implicitly_wait(3)
        #进入用户中心
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        #正常修改
        test ="TestNickname" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert actual1 == "成功"
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        actual2 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert actual2 == "成功"
        #生成随机的电话号码
        # self.driver.find_element(By.CSS_SELECTOR,"#setting_input_phoneNum").send_keys(test)
        # self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_phoneNum").click()
        # actual3 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        # print(actual3)
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_remark").click()
        actual4 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert actual4 == "成功"

        time.sleep(4)

        #异常修改--重复
        test ="TestNickname" + datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        time.sleep(1)
        a1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        time.sleep(1)
        assert a1 == "警告"

        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_email").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_email").click()
        time.sleep(1)
        a2 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert a2 == "警告"
        #生成随机的电话号码
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#settings_textarea_remark").send_keys(test)
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_remark").click()
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_remark").click()
        time.sleep(1)
        a4 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert a4 == "警告"

        #lisi-123  每次进行重置
    def UCSecert(self):
        self.driver.implicitly_wait(3)
        #正常修改
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lisi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        actual1 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert actual1 == "首页"
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        #重置
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()


        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("lisi")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()

        actual1 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title").text
        assert actual1 == "首页"
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()

        #异常测试
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("1111")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        time.sleep(1)
        s1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert s1 == "警告"

        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_newPassword").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_passwordRepeat").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
        time.sleep(1)
        s1 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert s1 == "提示"




uc = UC()
uc.UCMyblog()
uc.UCMycenter()
uc.UCSecert()

